package com.heatup.apt.management.service.coach.impl;

import com.baomidou.framework.service.impl.SuperServiceImpl;
import com.heatup.apt.common.dao.CoachCourseAdjustFeeMapper;
import com.heatup.apt.management.service.coach.CoachCourseAdjustFeeService;
import com.heatup.apt.model.coach.CoachCourseAdjustFee;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 *
 * CoachCourseAdjustFee 表数据服务层接口实现类
 *
 */
@Service
public class CoachCourseAdjustFeeServiceImpl extends SuperServiceImpl<CoachCourseAdjustFeeMapper, CoachCourseAdjustFee> implements CoachCourseAdjustFeeService {

    @Autowired
    private CoachCourseAdjustFeeMapper coachCourseAdjustFeeMapper;

    /**
     * 查询教练补充课时/扣费
     *
     * @param coachId 教练 ID
     * @param year 年
     * @param month 月
     * @return 教练补充课时/扣费
     */
    @Override
    public CoachCourseAdjustFee queryByCoachId(Integer coachId, Integer year, Integer month) {
        CoachCourseAdjustFee adjustFee = new CoachCourseAdjustFee();
        adjustFee.setCoachId(coachId);
        adjustFee.setAdjustYear(year);
        adjustFee.setAdjustMonth(month);
        return coachCourseAdjustFeeMapper.selectOne(adjustFee);
    }

    /**
     * 保存教练补充课时/扣费
     *
     * @param coachCourseAdjustFee 教练补充课时/扣费
     * @return true 保存成功 / false 失败
     */
    @Override
    public boolean save(CoachCourseAdjustFee coachCourseAdjustFee) {
        if (coachCourseAdjustFee != null) {

            if (coachCourseAdjustFee.getId() == null) {
                coachCourseAdjustFee.setCreatedTime(new Date());
                return coachCourseAdjustFeeMapper.insertSelective(coachCourseAdjustFee) > 0;
            } else {
                coachCourseAdjustFee.setUpdatedTime(new Date());
                return coachCourseAdjustFeeMapper.updateById(coachCourseAdjustFee) > 0;

            }
        }

        return false;
    }
}